package com.mdmedia.cms.dao.impl;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.mdmedia.cms.dao.IBaseDao;
import com.mdmedia.common.dao.ICommonDaoService;
import com.mdmedia.common.dao.PageResults;

public class BaseDaoImpl<T extends Object> implements IBaseDao<T>{

	@SuppressWarnings("rawtypes")
	@Autowired
	@Qualifier("commonDaoService")
	private ICommonDaoService commonDaoService;
	
	@SuppressWarnings("unchecked")
	@Override
	public Boolean createObject(T obj) throws Exception {
		commonDaoService.save(obj);
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Boolean deleteObject(String id) throws Exception {
		// TODO Auto-generated method stub
		commonDaoService.delete(this.queryObject(id));
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Boolean deleteObject(T obj) throws Exception {
		// TODO Auto-generated method stub
		commonDaoService.delete(obj);
		return null;
	}
	public List<T> queryDataList(String select ,String hql)throws Exception{
		if(null==select||"".equals(select)){
			return  commonDaoService.getListByHQL(hql);
		}
		else{
			return  commonDaoService.getListByHQL(select + hql);
		}
		
	}
	@SuppressWarnings("unchecked")
	@Override
	public PageResults<T> queryDataList(String hql, String countHql,int pageNo, int pageSize, Object... values) throws Exception{
		return  commonDaoService.findPageByFetchedHql(hql, countHql, pageNo, pageSize, values);
	}
	@Override
	public T queryObject(String id) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings("rawtypes")
	public ICommonDaoService getCommonDaoService() {
		return commonDaoService;
	}

	@SuppressWarnings("rawtypes")
	public void setCommonDaoService(ICommonDaoService commonDaoService) {
		this.commonDaoService = commonDaoService;
	}

	
	
}
